import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from dp.commons import TDP, RDP, PDP, set_fig_font, mre, mae, rmse

set_fig_font()


def read_file(file):
    data = pd.read_csv(file, header=None, usecols=[0]).to_numpy().reshape(1, -1)[0]
    return data


def plot():
    rdp_files = [
        "experiments/query/wine/s1e0.03.csv",
        "experiments/query/wine/s1e0.05.csv",
        "experiments/query/wine/s1e0.1.csv",
        "experiments/query/wine/s1e0.3.csv",
        "experiments/query/wine/s1e0.5.csv",
        "experiments/query/wine/s1e0.8.csv",
        "experiments/query/wine/s1e1.csv",
    ]

    tdp_files = [
        "experiments/query/wine/tdp_s1e0.03.csv",
        "experiments/query/wine/tdp_s1e0.05.csv",
        "experiments/query/wine/tdp_s1e0.1.csv",
        "experiments/query/wine/tdp_s1e0.3.csv",
        "experiments/query/wine/tdp_s1e0.5.csv",
        "experiments/query/wine/tdp_s1e0.8.csv",
        "experiments/query/wine/tdp_s1e1.csv",
    ]

    pdp_files = [
        "experiments/query/wine/pdp_s1e0.03.csv",
        "experiments/query/wine/pdp_s1e0.05.csv",
        "experiments/query/wine/pdp_s1e0.1.csv",
        "experiments/query/wine/pdp_s1e0.3.csv",
        "experiments/query/wine/pdp_s1e0.5.csv",
        "experiments/query/wine/pdp_s1e0.8.csv",
        "experiments/query/wine/pdp_s1e1.csv",
    ]
    epsilon = [0.03, 0.05, 0.1, 0.3, 0.5, 0.8, 1]

    truth = read_file("experiments/query/wine/truth.csv")
    rdp_predictions = [read_file(f) for f in rdp_files]
    rdp_rmses = [rmse(truth, p) for p in rdp_predictions]
    rdp_maes = [mae(truth, p) for p in rdp_predictions]
    rdp_mres = [mre(truth, p) for p in rdp_predictions]

    tdp_predictions = [read_file(f) for f in tdp_files]
    tdp_rmses = [rmse(truth, p) for p in tdp_predictions]
    tdp_maes = [mae(truth, p) for p in tdp_predictions]
    tdp_mres = [mre(truth, p) for p in tdp_predictions]

    pdp_predictions = [read_file(f) for f in pdp_files]
    pdp_rmses = [rmse(truth, p) for p in pdp_predictions]
    pdp_maes = [mae(truth, p) for p in pdp_predictions]
    pdp_mres = [mae(truth, p) for p in pdp_predictions]

    plt.plot(epsilon, tdp_rmses, label=TDP)
    plt.plot(epsilon, pdp_rmses, label=PDP)
    plt.plot(epsilon, rdp_rmses, label=RDP)
    plt.legend()
    plt.show()

    plt.plot(epsilon, tdp_maes, label=TDP)
    plt.plot(epsilon, pdp_maes, label=PDP)
    plt.plot(epsilon, rdp_maes, label=RDP)
    plt.legend()
    plt.show()

    plt.plot(epsilon, tdp_mres, label=TDP)
    plt.plot(epsilon, pdp_mres, label=PDP)
    plt.plot(epsilon, rdp_mres, label=RDP)
    plt.legend()
    plt.show()


if __name__ == "__main__":
    plot()
